/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

//import java.awt.Graphics2D;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Niels Leguit <niels.leguit at hva.nl>
 * @version $Id: imageStreamHelper.java,v 1.0 2012/05/01 $
 * bron: http://www.programcreek.com/downloads/convert-image-to-byte.txt
 */
public class imageStreamHelper {

    static byte[] advImageBytes;
    static File advImageFile;

    public static byte[] imageToByteStream(File fileAdvImage) throws FileNotFoundException {

        //create FileInputStream which obtains input bytes from a file in a file system
        //FileInputStream is meant for reading streams of raw bytes such as image data.
        FileInputStream fis = new FileInputStream(fileAdvImage);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        try {
            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);
                //no doubt here is 0
                /*
                 * Writes len bytes from the specified byte array starting at
                 * offset off to this byte array output stream.
                 */
                System.out.println("read " + readNum + " bytes,");
            }
        } catch (IOException ex) {
            Logger.getLogger(imageStreamHelper.class.getName()).log(Level.SEVERE, null, ex);
        }
        //bytes is the ByteArray we need
        advImageBytes = bos.toByteArray();

        return advImageBytes;
    } // einde plaatjes code

}